package other;

import java.util.Scanner;

public class Sqrt{
	static double E=0.001;//精度设置
	public static void main(String [] args){
		Scanner s=new Scanner(System.in);
		System.out.println("Please enter a real number:");
		double number;
//		int count=0;
		number=s.nextDouble();
		double result=Search(number,1);
		System.out.println(number+"的平方根是："+result);
		
	}
	
	public static double Search(double number,int count){
		double start=1;
		double end=number;
//		int count=0;
		while(true){
			count++;
			double mid=(start+end)/2;
			if(mid*mid-number<=E&&mid*mid-number>=-E)
				return mid;
			if(mid*mid-number>E)end=mid;
			else start=mid;
			System.out.println("迭代次数为"+count);
		}
	}
}